package com.bigegg.employee.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.bigegg.employee.domain.BoardPost;
import com.bigegg.employee.service.IBoardPostService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公告职位Controller
 * 
 * @author sun
 * @date 2022-08-15
 */
@RestController
@RequestMapping("/board/post")
public class BoardPostController extends BaseController
{
    @Autowired
    private IBoardPostService boardPostService;

    /**
     * 查询公告职位列表
     */
    @PreAuthorize("@ss.hasPermi('employee:post:list')")
    @GetMapping("/list")
    public TableDataInfo list(BoardPost boardPost)
    {
        startPage();
        List<BoardPost> list = boardPostService.selectBoardPostList(boardPost);
        return getDataTable(list);
    }

    /**
     * 导出公告职位列表
     */
    @PreAuthorize("@ss.hasPermi('employee:post:export')")
    @Log(title = "公告职位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BoardPost boardPost)
    {
        List<BoardPost> list = boardPostService.selectBoardPostList(boardPost);
        ExcelUtil<BoardPost> util = new ExcelUtil<BoardPost>(BoardPost.class);
        util.exportExcel(response, list, "公告职位数据");
    }

    /**
     * 获取公告职位详细信息
     */
    @PreAuthorize("@ss.hasPermi('employee:post:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(boardPostService.selectBoardPostById(id));
    }

    /**
     * 新增公告职位
     */
    @PreAuthorize("@ss.hasPermi('employee:post:add')")
    @Log(title = "公告职位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BoardPost boardPost)
    {
        return toAjax(boardPostService.insertBoardPost(boardPost));
    }

    /**
     * 修改公告职位
     */
    @PreAuthorize("@ss.hasPermi('employee:post:edit')")
    @Log(title = "公告职位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BoardPost boardPost)
    {
        return toAjax(boardPostService.updateBoardPost(boardPost));
    }

    /**
     * 删除公告职位
     */
    @PreAuthorize("@ss.hasPermi('employee:post:remove')")
    @Log(title = "公告职位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(boardPostService.deleteBoardPostByIds(ids));
    }
}
